package com.designpatterns.proxy.remote;

import java.rmi.Naming;

/**
 * @author Brook
 */
public class GumballMachineTestDrive {
    public static void main(String[] args) {
        int count = 0;
        if(args.length < 2) {
            System.out.println("GumballMachine <name><inventory>");
            System.exit(1);
        }

        count = Integer.parseInt(args[1]);

        GumballMachine gumballMachine = null;
        try {
            gumballMachine = new GumballMachine(args[0], count);
            Naming.rebind(args[0]+"/gumballMachine", gumballMachine);
            System.out.println("绑定成功");
        } catch (Exception e) {
            e.printStackTrace();
        }
        GumballMonitor gumballMonitor = new GumballMonitor(gumballMachine);


        /*System.out.println(gumballMachine);

        gumballMachine.insertQuarter();
        gumballMachine.turnCrank();

        System.out.println(gumballMachine);

        gumballMachine.insertQuarter();
        gumballMachine.turnCrank();
        gumballMachine.insertQuarter();
        gumballMachine.turnCrank();

        System.out.println(gumballMachine);*/

        gumballMonitor.report();

    }
}
